package cn.bytecollege.user.controller;

import cn.bytecollege.common.constant.Resource;
import cn.bytecollege.common.entity.Cart;
import cn.bytecollege.common.entity.Category;
import cn.bytecollege.common.entity.Cuisine;
import cn.bytecollege.user.service.CartService;
import cn.bytecollege.user.service.CategoryService;
import cn.bytecollege.user.service.CuisineService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "UserIndexController", value = "/user/userIndex")
public class UserIndexController extends HttpServlet {
    private CuisineService cuisineService = null;
    private CategoryService categoryService = null;
    private CartService cartService = null;
    public UserIndexController(){
        categoryService = new CategoryService();
        cuisineService = new CuisineService();
        cartService = new CartService();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Cuisine> list = cuisineService.find();
        List<Category> categoryList = categoryService.findCategory();
        List<Cart> cartList = cartService.find();

        request.setAttribute("categoryList",categoryList);
        request.setAttribute("list",list);
        request.setAttribute("cartList",cartList);
        request.getRequestDispatcher(Resource.PAGE_LOCATION+"/user/index.jsp").forward(request,response);
    }
}
